package com.kyc.kycxkplaygame.entity.digital;

import com.kyc.kycxkplaygame.R;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created by Administrator on 2018/7/16.
 */

public class DigitalTetrisBlock {
    //private static final int TYPE_SUM = 7;
    public int blockType, blockDirection; // 方块种类，方块朝向
    public EblockType eblockType;

    //private int color; // 方块颜色
    //One, two, three, four, five, six, seven, eight, nine, ten, zero
    public enum EblockType{BLOCK_TYPE_ZERO,
        BLOCK_TYPE_ONE ,BLOCK_TYPE_TWO,
        BLOCK_TYPE_THREE,BLOCK_TYPE_FOUR,
        BLOCK_TYPE_FIVE,BLOCK_TYPE_SIX,
        BLOCK_TYPE_SEVEN,BLOCK_TYPE_EIGHT,
        BLOCK_TYPE_NINE,BLOCK_TYPE_TEN,
    }

    public int[] zero = {0};
    public int[] one = {1,11,21,31,41,51,61,71,81,91};
    public int[] two = {2,12,22,32,42,52,62,72,82,92};
    public int[] three = {3,13,23,33,43,53,63,73,83,93};
    public int[] four = {4,14,24,34,44,54,64,74,84,94};
    public int[] five = {5,15,25,35,45,55,65,75,85,95};
    public int[] six = {6,16,26,36,46,56,66,76,86,96};
    public int[] seven = {7,17,27,37,47,57,67,77,87,97};
    public int[] eight = {8,18,28,38,48,58,68,78,88,98};
    public int[] nine = {9,19,29,39,49,59,69,79,89,99};
    public int[] ten = {10,100};


    private static final int color[] = {
            R.color.c_ffa4c0,
            R.color.c75cf3,
            R.color.c_0c36d2,
            R.color.c_f60fcd,
            R.color.c_2bd0d6,
            R.color.c_1fac7f,
            R.color.f54a15,
            R.color.c_5f9d0e,
            R.color.c_2095f2,
            R.color.c_ffee9900,
            R.color.colorRed};

    private int x, y; // 方块坐标

    public DigitalTetrisBlock() {

    }

    public DigitalTetrisBlock(int x, int y) {
        this.x = x;
        this.y = y;
    }

    public List<DigitalBlockUnit> getUnits(int x, int y, EblockType eblockType) {
        this.x = x;
        this.y = y;
        this.eblockType = eblockType;
        return returnUnit();
    }

    /**
     * 随机产生一种方块
     *
     * @return
     */
    public List<DigitalBlockUnit> returnUnit() {
        List<DigitalBlockUnit> units = new ArrayList<DigitalBlockUnit>(); // 方块组成部分
        //blockType = (int) (Math.random() * TYPE_SUM) + 1; // 随机生成一个种类
        //blockDirection = 1; // 默认初始方向
        //color = (int) (Math.random() * 4) + 1; // 随机生成一个颜色
        units.clear();
        switch (eblockType) {
            case BLOCK_TYPE_ZERO:// 横线
                for (int i = 0; i < 5; i++) {
                    Random random = new Random();
                    int nextInt = random.nextInt(3);
                    units.add(new DigitalBlockUnit(x + (-2 + i) * DigitalBlockUnit.UNIT_SIZE, y, color[nextInt],""+nextInt));
                }
                break;
            case BLOCK_TYPE_ONE:
                for (int i = 0; i < 5; i++) {
                    units.add(new DigitalBlockUnit(x + (-2 + i) * DigitalBlockUnit.UNIT_SIZE, y, color[1],""+i));
                }
                break;
            case BLOCK_TYPE_TWO:
                for (int i = 0; i < 5; i++) {
                    units.add(new DigitalBlockUnit(x + (-2 + i) * DigitalBlockUnit.UNIT_SIZE, y, color[2],""+i));
                }
                break;
            case BLOCK_TYPE_THREE:
                for (int i = 0; i < 5; i++) {
                    units.add(new DigitalBlockUnit(x + (-2 + i) * DigitalBlockUnit.UNIT_SIZE, y, color[3],""+i));
                }
                break;
            case BLOCK_TYPE_FOUR:
                for (int i = 0; i < 5; i++) {
                    units.add(new DigitalBlockUnit(x + (-2 + i) * DigitalBlockUnit.UNIT_SIZE, y, color[4],""+i));
                }
                break;
            case BLOCK_TYPE_FIVE:
                for (int i = 0; i < 5; i++) {
                    units.add(new DigitalBlockUnit(x + (-2 + i) * DigitalBlockUnit.UNIT_SIZE, y, color[5],""+i));
                }
                break;
            case BLOCK_TYPE_SIX:
                for (int i = 0; i < 5; i++) {
                    units.add(new DigitalBlockUnit(x + (-2 + i) * DigitalBlockUnit.UNIT_SIZE, y, color[6],""+i));
                }
                break;
            case BLOCK_TYPE_SEVEN:
                for (int i = 0; i < 5; i++) {
                    units.add(new DigitalBlockUnit(x + (-2 + i) * DigitalBlockUnit.UNIT_SIZE, y, color[7],""+i));
                }
                break;
            case BLOCK_TYPE_EIGHT:
                for (int i = 0; i < 5; i++) {
                    units.add(new DigitalBlockUnit(x + (-2 + i) * DigitalBlockUnit.UNIT_SIZE, y, color[8],""+i));
                }
                break;
            case BLOCK_TYPE_NINE:
                for (int i = 0; i < 5; i++) {
                    units.add(new DigitalBlockUnit(x + (-2 + i) * DigitalBlockUnit.UNIT_SIZE, y, color[9],""+i));
                }
                break;
            case BLOCK_TYPE_TEN:
                for (int i = 0; i < 5; i++) {
                    units.add(new DigitalBlockUnit(x + (-2 + i) * DigitalBlockUnit.UNIT_SIZE, y, color[10],""+i));
                }
                break;
        }
        return units;
    }
}
